<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import HeaderLogo from '@/components/header/HeaderLogo.vue';
import HeaderNav from '@/components/header/HeaderNav.vue';
import HeaderSearch from '@/components/header/HeaderSearch.vue';
import HeaderUser from '@/components/header/HeaderUser.vue';
import HeaderCodeLink from '@/components/header/HeaderCodeLink.vue';
import HeaderLang from '@/components/header/HeaderLang.vue';
import HeaderTheme from '@/components/header/HeaderTheme.vue';
// -------------------- 出现横向滚动条时，头部导航自适应 --------------------
const headerLeft = ref(0);
const onScroll = () => {
  headerLeft.value = window.scrollX;
};
onMounted(() => {
  window.addEventListener('scroll', onScroll);
});
onUnmounted(() => {
  window.removeEventListener('scroll', onScroll);
});
</script>

<template>
  <div class="app-header">
    <div class="app-header-wrap" :style="{ right: `${headerLeft}px` }">
      <div class="header-content">
        <div class="header-left">
          <!-- LOGO -->
          <HeaderLogo />
          <!-- 导航 -->
          <HeaderNav />
        </div>

        <div class="header-right">
          <ClientOnly>
            <!-- 搜索框 -->
            <HeaderSearch />
            <!-- 代码仓 -->
            <HeaderCodeLink />
            <!-- 语言切换 -->
            <!-- <HeaderLang />-->
            <!-- 主题切换 -->
            <HeaderTheme />
            <!-- 用户 -->
            <HeaderUser />
          </ClientOnly>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.app-header {
  height: var(--layout-header-height);
  color: var(--o-color-info1);
  background-color: var(--o-color-fill2);
  position: fixed;
  top: 0;
  z-index: var(--layout-header-z-index);
  width: 100%;
  display: flex;
  &::before {
    top: 0;
    bottom: 0;
    right: 0;
    box-shadow: 0 3px 8px rgba(var(--o-mixedgray-14), 0.05);
    content: '';
    left: 0;
    pointer-events: none;
    position: absolute;
  }
}

.app-header-wrap {
  position: relative;
  height: 100%;
  width: var(--grid-content-width);
  margin: 0 auto;
}

.header-content {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: auto;
}

.header-left,
.header-right {
  height: 100%;
  display: flex;
  align-items: center;
  animation: anim-header-trans-in var(--o-duration-xl);
}

@keyframes anim-header-trans-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.header-logo {
  height: 100%;
  display: flex;
  align-items: center;
  cursor: pointer;
}
@include respond-to('<=pad_v') {
  .app-header {
    display: none;
  }
}
</style>
